package com.jiamao.goplay.ui.user.vm;

import android.os.Bundle;
import android.view.View;

import com.jiamao.goplay.bean.PlaceWantGoItem;
import com.jiamao.goplay.config.Config;
import com.jiamao.goplay.ui.discover.AddrDetailFragment;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;
import androidx.databinding.ObservableInt;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.MultiItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.utils.KLog;
import me.goldze.mvvmhabit.utils.SPUtils;

public class UserOtherGotoItemVM extends MultiItemViewModel {

    public ObservableField<String> title = new ObservableField<>("");
    public ObservableField<String> nums = new ObservableField<>("0人邀请我");
    public ObservableField<String> imgUrl = new ObservableField<>("");

    public ObservableField<String> yqStr = new ObservableField<>("邀请他去");
    public ObservableField<List<String>> list = new ObservableField<List<String>>();
    public ObservableInt ypdBtnVisibility = new ObservableInt(View.GONE);
    public ObservableInt yqBtnVisibility = new ObservableInt(View.GONE);
    public ObservableInt jsyqBtnVisibility = new ObservableInt(View.GONE);
    public ObservableInt yyqBtnVisibility = new ObservableInt(View.GONE);
    public ObservableInt yqnBtnVisibility = new ObservableInt(View.GONE);
    private String id,uid,ivid;
    private UserWantGotoVM gotoVM;
    public UserOtherGotoItemVM(@NonNull BaseViewModel viewModel,String Meuid, PlaceWantGoItem item,int sex) {
        super(viewModel);
        if (viewModel instanceof UserWantGotoVM ){
            this.gotoVM = (UserWantGotoVM) viewModel;
        }

        if (item == null){
            return;
        }
        yqStr.set("邀请"+(sex==1?"他":"她")+"去");
        ivid = item.getInvID();
        id = item.getPlaceId();
        imgUrl.set(item.getPlaceCover());

        title.set(item.getPlaceName());
        list.set(item.getInviteUserAvatar());

        this.uid = Meuid;

        String uids = SPUtils.getInstance().getString(Config.UID);
        nums.set(item.getCity()+",  "+item.getInviteUser()+"人想去");
        if (uids.equals(Meuid)){
              return;
        }
        switch (item.getStatus()){
            case 0:
                if (sex==1){
                    yqnBtnVisibility.set(View.VISIBLE);
                }else {
                    yqBtnVisibility.set(View.VISIBLE);
                }

                nums.set(item.getCity()+",  "+item.getInviteUser()+"人想去");
               // yqBtnVisibility.set(View.VISIBLE);
                break;
            case 1:
                nums.set(item.getCity()+",  "+item.getInviteUser()+"人想去");
                jsyqBtnVisibility.set(View.VISIBLE);
                break;
            case 2:
                nums.set(item.getCity()+",  "+item.getInviteUser()+"人想去");
                ypdBtnVisibility.set(View.VISIBLE);
                break;
            case 3:
                nums.set(item.getCity()+",  "+item.getInviteUser()+"人想去");
                yyqBtnVisibility.set(View.VISIBLE);
                break;
            default:
                nums.set(item.getCity()+",  "+item.getInviteUser()+"人想去");
                break;

        }
    }

    //条目的点击事件
    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bd = new Bundle();
            bd.putString("id",id);
           viewModel.startContainerActivity(AddrDetailFragment.class.getCanonicalName(),bd);
        }
    });

    //条目的点击事件
    public BindingCommand ypdClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

            if (viewModel instanceof  UserOtherWantGotoVM){
                ((UserOtherWantGotoVM)viewModel).startChat(uid);
            }
            else if(viewModel instanceof  UserOtherInfoVM){
                ((UserOtherInfoVM)viewModel).startChat(uid);
            }
           //  gotoVM.removeCloection(id, UserOhterGotoItemVM.this);
           // viewModel.startContainerActivity(AddrDetailFragment.class.getCanonicalName(),bd);
        }
    });

    //条目的点击事件
    public BindingCommand jsyqClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

            if (viewModel instanceof  UserOtherWantGotoVM){
                ((UserOtherWantGotoVM)viewModel).jieshouyaoqing(ivid,UserOtherGotoItemVM.this);
            }
            else if(viewModel instanceof  UserOtherInfoVM){
                ((UserOtherInfoVM)viewModel).jieshouyaoqing(ivid,UserOtherGotoItemVM.this);
            }
            // ((AddrDetailVM)viewModel).jieshouyaoqing(uid);
        }
    });


    //条目的点击事件
    public BindingCommand yqClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

            KLog.d("html  asdasd "+viewModel);
            if (viewModel instanceof  UserOtherWantGotoVM){
                ((UserOtherWantGotoVM)viewModel).yaoqing(id,UserOtherGotoItemVM.this);
            }
            else if(viewModel instanceof  UserOtherInfoVM){
                ((UserOtherInfoVM)viewModel).yaoqing(id,UserOtherGotoItemVM.this);
            }
            //    ((AddrDetailVM)viewModel).yaoqing(uid);
            // viewModel.startContainerActivity(SearchFragment.class.getCanonicalName());
        }
    });





}
